<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\points\Entity\Points;

class PointItemGold extends PointItem {

  protected function setValue() {
    parent::setValue();
    if ($this->entity instanceof Points) {
      $value = [
        'gold' => $this->getGold($this->entity),
      ];
      $this->merge($value);
    }
  }

  protected function getGold(Points $points) {
    if ($points->point <= 0) {
      return $points->point;
    }
    return "+{$points->point}";
  }
}
